package com.itheima.health.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.health.dao.PermissionDao;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.pojo.Permission;
import com.itheima.health.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = PermissionService.class)
@Transactional
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    private PermissionDao permissionDao;


    //分页查询
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        //分页查询，使用mybatis的分页助手插件实现分页
        PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        Page<Permission> page = permissionDao.findPage(queryPageBean.getQueryString());

        return new PageResult(page.getTotal(), page.getResult());
    }

    //新增权限
    @Override
    public void add(Permission permission) {
        permissionDao.add(permission);
    }

    //删除权限
    @Override
    public void delete(Integer id) {
        permissionDao.delete(id);
    }

    //编辑表单数据回显
    @Override
    public Permission findById(Integer id) {
        return permissionDao.findById(id);
    }

    //编辑权限
    @Override
    public void updatePermission(Permission permission) {
        permissionDao.updatePermission(permission);
    }

    //查询所有权限
    @Override
    public List<Permission> findAll() {
        return permissionDao.findAll();
    }
}
